/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package uk.ac.cam.can.generalisator;

import java.util.Random;

/**
 *
 * @author Thomas
 */
public class GenZip implements Generalisator{
    @Override
    public String gen(String value){
        value = value.replace(" ", "");
        int olength=value.length();
        for(int i = value.length()-1; i>=0; i--){
            if(value.charAt(i)!='*'){
                value = value.substring(0, i);
                break;
            }
        }
        int length=olength-value.length();
        for(int i = 0; i < length; i++)
            value+="*";
        return value;
    }

    @Override
    public int getMaxGeneralisation() {
        return 7;
    }

    @Override
    public double getLength(String value) {
        int pos = value.indexOf("*");
        return 7.0-(double)pos;
    }

    @Override
    public double getMaxLength() {
        return 7.0;
    }

    @Override
    public String getUngeneralisation(String value) {
        Random rand = new Random(System.nanoTime());
        int pos = value.indexOf("*");
        if(pos==0)
            return "CB5 8BL";
        else{
            value= value.substring(0, pos);
            value+=rand.nextInt(10);
            for(int i = value.length(); i < 7; i++){
                value+="*";
            }
            return value;
        }
    }

    @Override
    public int getGeneralisationLevel(String value) {
        int pos = value.indexOf("*");
        return 6-pos;
    }
    
    
    
}
